import json

from requests.cookies import RequestsCookieJar
from selenium import webdriver
from selenium.webdriver.common.by import By

from util.constant import Constant

global driver


def send_message_code(telephone):
    global driver
    driver = webdriver.Edge(executable_path=Constant.DRIVER_PATH)
    driver.implicitly_wait(5)
    driver.get("https://tb.ele.me/wow/msite/act/login")
    driver.switch_to.frame("alibaba-login-box")
    driver.find_element(By.ID, "fm-sms-login-id").send_keys(telephone)
    driver.find_element(By.CLASS_NAME, "send-btn-link").click()


def get_cookies():
    cookies = driver.get_cookies()
    with open("cookie.txt", 'w') as f:
        json.dump(cookies, f)
    return cookies
